package com.dubbo.mapper.auth;

import com.dubbo.domain.auth.Area;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;
import java.util.Map;

/**
 * 地区
 * @author lihongwu
 * 2019年1月7日 下午4:40:24
 */
public interface AreaMapper extends Mapper<Area> {

	/**
	 * 获取省列表
	 *
	 * @author lihongwu
	 * 2019年1月7日 下午4:53:33
	 * @param pageStart
	 * @param pageTotal
	 * @return
	 */
	@Select("SELECT" + 
			"	ta.id," + 
			"	ta.`name`," + 
			"	ta.parentid," + 
			"	ta.parentname," + 
			"	ta.areacode," + 
			"	ta.zipcode," + 
			"	ta.depth" + 
			" FROM" + 
			"	t_area ta" + 
			" WHERE ta.depth = 1" + 
			" LIMIT #{pageStart},#{pageTotal}")
	List<Map<String, Object>> getProvinceList(@Param("pageStart") Long pageStart, @Param("pageTotal") Long pageTotal);
	
	/**
	 * 获取省列表总数
	 *
	 * @author lihongwu
	 * 2019年1月7日 下午4:54:55
	 * @return
	 */
	@Select("SELECT" + 
			"	COUNT(ta.id)" + 
			" FROM" + 
			"	t_area ta" + 
			" WHERE ta.depth = 1")
	Long getProvinceListCount();

	/**
	 * 根据parentId获取下级列表
	 *
	 * @author lihongwu
	 * 2019年1月7日 下午5:04:36
	 * @param parentId
	 * @param pageStart
	 * @param pageTotal
	 * @return
	 */
	@Select("SELECT" + 
			"	ta.id," + 
			"	ta.`name`," + 
			"	ta.parentid," + 
			"	ta.parentname," + 
			"	ta.areacode," + 
			"	ta.zipcode," + 
			"	ta.depth" + 
			" FROM" + 
			"	t_area ta" + 
			" WHERE ta.parentid = #{parentId}" + 
			" LIMIT #{pageStart},#{pageTotal}")
	List<Map<String, Object>> getSubordinateList(@Param("parentId") Long parentId
            , @Param("pageStart") Long pageStart
            , @Param("pageTotal") Long pageTotal);
	
	/**
	 * 根据parentId获取下级列表总数量
	 *
	 * @author lihongwu
	 * 2019年1月7日 下午5:05:50
	 * @param parentId
	 * @return
	 */
	@Select("SELECT" + 
			"	COUNT(ta.id)" + 
			" FROM" + 
			"	t_area ta" + 
			" WHERE ta.parentid = #{parentId}")
	Long getSubordinateListCount(@Param("parentId") Long parentId);
}